package com.blog.dao;

import com.blog.bean.QueryCallback;
import com.blog.util.Util;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ThumbsUpDao {

    public boolean select(int blogId, int uid) throws SQLException {
        String sql = "select * from thumbs_up where blog_id = " + blogId + " and uid = " + uid;
        System.out.println(sql);
        return (boolean) JdbcUtil.executeQuery(sql, new QueryCallback() {
            @Override
            public Object doResultHandle(ResultSet resultSet) throws SQLException {
                return resultSet.next();
            }
        });
    }

    public void thumbsUp(int blogId, int uid) throws SQLException {
        String sql = "insert into thumbs_up(uid, blog_id, create_time) values(" +
                uid + ", " +
                blogId + ", '" +
                Util.getNowDateString() + "')";
        System.out.println(sql);
        JdbcUtil.execute(sql);
    }

}
